package com.dawnling.androidutils.ui;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.blankj.utilcode.util.LogUtils;
import com.dawnling.androidutils.R;
import com.dawnling.androidutils.bean.BaseResponse;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

public class JsonAboutActivity extends AppCompatActivity {

    public static String json1 = "{\"code\":2000,\"message\":\"Operasi berjaya\",\"data\":[\"https://xxx.xx.xx/a.img\"]}";
    public static String json2 = "{\"code\":2000,\"message\":\"Operasi berjaya\",\"data\":[{\"id\":\"item1\",\"title\":\"查询缴费\",\"imageUrl\":\"https://xxx.xx.xx/a.img\",\"menuUrl\":\"https://xxx.xx.xx/a.img\",\"sortIndex\":1,\"createTime\":\"2020-08-28T09:04:47.000Z\",\"updateTime\":\"2020-08-28T09:04:47.000Z\",\"state\":0,\"remark\":\"title填写中文即可，系统会跟进语序代码自动翻译\"},{\"id\":\"item2\",\"title\":\"缴费历史\",\"imageUrl\":\"https://xxx.xx.xx/a.img\",\"menuUrl\":\"https://xxx.xx.xx/a.img\",\"sortIndex\":2,\"createTime\":\"2020-08-28T09:04:47.000Z\",\"updateTime\":\"2020-08-28T09:04:47.000Z\",\"state\":0,\"remark\":\"title填写中文即可，系统会跟进语序代码自动翻译\"},{\"id\":\"item3\",\"title\":\"找车\",\"imageUrl\":\"https://xxx.xx.xx/a.img\",\"menuUrl\":\"https://xxx.xx.xx/a.img\",\"sortIndex\":3,\"createTime\":\"2020-08-28T09:04:47.000Z\",\"updateTime\":\"2020-08-28T09:04:47.000Z\",\"state\":0,\"remark\":\"title填写中文即可，系统会跟进语序代码自动翻译\"},{\"id\":\"item4\",\"title\":\"车场信息\",\"imageUrl\":\"https://xxx.xx.xx/a.img\",\"menuUrl\":\"https://xxx.xx.xx/a.img\",\"sortIndex\":4,\"createTime\":\"2020-08-28T09:04:47.000Z\",\"updateTime\":\"2020-08-28T09:04:47.000Z\",\"state\":0,\"remark\":\"title填写中文即可，系统会跟进语序代码自动翻译\"}]}";
    public static String json3 = "{\"code\":2000,\"message\":\"Operasi berjaya\",\"data\":{}}";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_json_about);
    }

    private void parsingJsonStr(String jsonStr) {
        BaseResponse<Object> data = new Gson().fromJson(jsonStr, new TypeToken<BaseResponse<Object>>() {
        }.getType());
        LogUtils.e("data.code：" + data.code);
        LogUtils.e("data.message：" + data.message);
        Object data1 = data.data;
        LogUtils.e("data.data：" + data1 + "///data.data.toString()：" + data1.toString());
    }

    public void btn1(View v) {
        parsingJsonStr(json1);
    }

    public void btn2(View v) {
        parsingJsonStr(json2);
    }

    public void btn3(View v) {
        parsingJsonStr(json3);
    }
}
